﻿<cfsilent>
	<cfscript>
		
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		
		subjectId = event.getArg("SBJ");
		grade = event.getArg("GRD");
		studentId = event.getArg("STU");
	
		/* 学生成绩明细 */
		sql = "SELECT 
						b.cid, b.course_name, b.course_credit, 
						a.scm_id, 
						a.retaking, a.mark_mode, 
						a.mark_result, a.mark_note, 
						a.mark_resit, a.mark_renote, a.mark_resit_limit, 
						c.prop_id, c.prop_name, 
						d.rep_desc, d.rep_mark 
					FROM t_student_mark a 
						 INNER JOIN t_course b ON b.cid = a.cid 
						 INNER JOIN t_course_prop c ON c.prop_id = a.prop_id 
						 LEFT OUTER JOIN t_mark_replace d ON d.scm_id = a.scm_id 
					WHERE 
						  a.stu_id = :studentId 
					ORDER BY b.course_name ";
		
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
		rs_mark = queryObj.execute( sql=sql ).getResult();


		/* 读取尚需完成的必修课 */
		sql = "SELECT 
					b.cid, b.course_name, b.course_credit 
					FROM t_mark_need a 
						INNER JOIN t_course b ON b.cid = a.cid 
					WHERE 
						a.stu_id = :studentId 
						AND 
						( a.gdc = 'CPR' OR a.gdc = 'CBR' ) 
					ORDER BY b.course_name ";
							
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			
		rs_mark_need = queryObj.execute( sql=sql ).getResult();
		
		
		/* 读取通过课程 */
		sql = "SELECT *
					FROM query
					WHERE mark_result >= 60 OR mark_resit >= 60 ";
							
		queryObj = new Query( dbtype="query" );
		queryObj.setAttributes( query=rs_mark );

		rs_pass = queryObj.execute( sql=sql ).getResult();
		

		/* 读取未通过必修课程 且这些课程没有标注替代 */
		sql = "SELECT *
					FROM query
					WHERE 
						mark_result < 60 AND mark_resit < 60 
						AND 
						rep_mark IS NULL 
						AND 
						prop_id = '1' ";

		queryObj = new Query( dbtype="query" );
		queryObj.setAttributes( query=rs_mark );

		rs_failure = queryObj.execute( sql=sql ).getResult();
		
		
		/* 读取未通过选修课程 且这些课程没有标注替代 */
		sql = "SELECT *
					FROM query
					WHERE 
						mark_result < 60 AND mark_resit < 60 
						AND 
						rep_mark IS NULL 
						AND 
						prop_id <> '1' 
				ORDER BY prop_name, course_name ";

		queryObj = new Query( dbtype="query" );
		queryObj.setAttributes( query=rs_mark );

		rs_failure_option = queryObj.execute( sql=sql ).getResult();
		
		
		/* 读取标注替代的课程 */
		sql = "SELECT *
					FROM query
					WHERE 
						rep_mark IS NOT NULL";

		queryObj = new Query( dbtype="query" );
		queryObj.setAttributes( query=rs_mark );

		rs_replace = queryObj.execute( sql=sql ).getResult();
		
		
		/* 检查是否可以自动成绩替代标注 */
		
		failureAutoReplaced = false;
		
		for ( a=1; a LTE rs_failure.recordCount; a++ ) {
			for ( b=1; b LTE rs_pass.recordCount; b++ ) {

				if ( rs_failure["cid"][a] eq rs_pass["cid"][b] OR rs_failure["course_name"][a] eq rs_pass["course_name"][b] ) {
					failureAutoReplaced = true;
					break;
					break;
				}
				
			}
		}		
		
		failureOptAutoReplaced = false;
		
		for ( a=1; a LTE rs_failure_option.recordCount; a++ ) {
			for ( b=1; b LTE rs_pass.recordCount; b++ ) {

				if ( rs_failure_option["cid"][a] eq rs_pass["cid"][b] OR rs_failure_option["course_name"][a] eq rs_pass["course_name"][b] ) {
					failureOptAutoReplaced = true;
					break;
					break;
				}
				
			}
		}		
		
		
		passArgs = structNew();
		structInsert( passArgs, "SBJ", subjectId, true );
		structInsert( passArgs, "GRD", grade, true );
		structInsert( passArgs, "STU", studentId, true );

	</cfscript>
</cfsilent>

					<div class="noticeBlock">
						<h3>各项成绩分类统计</h3>
						<p><span class="img icon16x16 message"></span>下列是该学生各项成绩的归类显示, 对于毕业生而言, 所有的必修课成绩应该通过考核, 通过培养方案所规定的所有必修课程需找到对应的成绩.</p>
					</div>
					
					<div class="UIColumns">
						
						<div class="col2 first">
							
							<div class="noticeBlock">
								<h2 class="UILeadHead markPassed"><span>已通过课程</span></h2>
							</div>
							
							<!--- 已通过课程 --->
							<table class="UItable markPassed">
								
								<tr class="cellDivide cellHeader">
									<td>课程</td>
									<td width="30">性质</td>
									<td width="30">学分</td>
									<td width="30">成绩</td>
								</tr>
								
								<tbody>
									<cfloop query="rs_pass">

										<cfset markFinal = markAdvice.getMarkResult( rs_pass.mark_mode, rs_pass.mark_result, rs_pass.mark_note, rs_pass.mark_resit, rs_pass.mark_renote, rs_pass.mark_resit_limit ) />
										<tr class="cellDivide">
											<td><cfoutput>#rs_pass.course_name#</cfoutput></td>
											<td><cfoutput>#rs_failure.prop_name#</cfoutput></td>
											<td align="center"><span class="number"><cfoutput>#numberFormat( rs_pass.course_credit, "_.__" )#</cfoutput></span></td>
											<td align="center">
												<cfif isNumeric(markFinal)>
														<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
													<cfelse>
														<cfoutput>#markFinal#</cfoutput>
												</cfif>
											</td>
										</tr>
									</cfloop>
								</tbody>
								
							</table>
							
						</div>
						
						<div class="col2 last">
							
							<cfif rs_mark_need.recordCount>
								
								<div class="noticeBlock">
									<h2 class="UILeadHead markNeed"><span>尚需完成的必修课</span></h2>
								</div>
								
								<!--- 培养方案规定的必修课 --->	
								<table class="UItable markNeed">
									
									<tr class="cellDivide cellHeader">
										<td>课程</td>
										<td width="30">学分</td>
										<td width="18"></td>
									</tr>
									
									<tbody>
										<cfloop query="rs_mark_need">
											
											<cfset structInsert( passArgs, "CID", rs_mark_need.cid, true ) />
											<tr class="cellDivide">
												<td><cfoutput>#rs_mark_need.course_name#</cfoutput></td>
												<td align="center"><span class="number"><cfoutput>#numberFormat( rs_mark_need.course_credit, "_.__" )#</cfoutput></span></td>
												<td><a title="指定替代课程" href="<cfoutput>#buildURL('signCourseReplace', passArgs)#</cfoutput>" class="operation linkCourse"></a></td>
											</tr>
								
										</cfloop>
										<!--- 移除额外参数 --->
										<cfset structDelete( passArgs, "CID", false ) />
									</tbody>
								
								</table>
								
							</cfif>
							
							<cfif rs_failure.recordCount>
							
								<div class="noticeBlock">
									<h2 class="UILeadHead markFailure"><span>未通过必修课</span></h2>
								</div>
								
								<cfif failureAutoReplaced>
									<div class="UIArrowHead orange">
										<h2>需要帮助您自动查找替换课程吗? <a href="<cfoutput>#buildURL('signMarkReplaceAutomaticDo', passArgs)#</cfoutput>">自动标注成绩</a></h2>
									</div>
								</cfif>
							
								<!--- 未通过课程 --->	
								<table class="UItable markFailure">
									
									<tr class="cellDivide cellHeader">
										<td>课程</td>
										<td width="30">性质</td>
										<td width="30">学分</td>
										<td width="30">成绩</td>
										<td width="18"></td>
									</tr>

									<tbody>
										<cfloop query="rs_failure">
								
											<cfset markFinal = markAdvice.getMarkResult( rs_failure.mark_mode, rs_failure.mark_result, rs_failure.mark_note, rs_failure.mark_resit, rs_failure.mark_renote, rs_failure.mark_resit_limit ) />
											<cfset structInsert( passArgs, "SCMID", rs_failure.scm_id, true ) />
											<tr class="cellDivide">
												<td><cfoutput>#rs_failure.course_name#</cfoutput></td>
												<td><cfoutput>#rs_failure.prop_name#</cfoutput></td>
												<td align="center"><span class="number"><cfoutput>#numberFormat( rs_failure.course_credit, "_.__" )#</cfoutput></span></td>
												<td align="center">
													<cfif isNumeric(markFinal)>
															<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
														<cfelse>
															<cfoutput>#markFinal#</cfoutput>
													</cfif>
												</td>
												<td><a title="指定替代成绩" href="<cfoutput>#buildURL('signMarkReplace', passArgs)#</cfoutput>" class="operation replaceCourse"></a></td>
											</tr>

										</cfloop>
										<!--- 移除额外参数 --->
										<cfset structDelete( passArgs, "SCMID", false ) />
									</tbody>
								
								</table>
							
							</cfif>
							
							
							<cfif rs_failure_option.recordCount>
							
								<div class="noticeBlock">
									<h2 class="UILeadHead markFailureOpt"><span>其它未通过课程</span></h2>
								</div>
								
								<cfif failureOptAutoReplaced>
									<div class="UIArrowHead orange">
										<h2>需要帮助您自动查找替换课程吗? <a href="<cfoutput>#buildURL('signMarkReplaceAutomaticDo', passArgs)#</cfoutput>">自动标注成绩</a></h2>
									</div>
								</cfif>
							
								<!--- 未通过课程 --->	
								<table class="UItable markFailureOpt">
									
									<tr class="cellDivide cellHeader">
										<td>课程</td>
										<td width="30">性质</td>
										<td width="30">学分</td>
										<td width="30">成绩</td>
										<td width="18"></td>
									</tr>

									<tbody>
										<cfloop query="rs_failure_option">
								
											<cfset markFinal = markAdvice.getMarkResult( rs_failure_option.mark_mode, rs_failure_option.mark_result, rs_failure_option.mark_note, rs_failure_option.mark_resit, rs_failure_option.mark_renote, rs_failure_option.mark_resit_limit ) />
											<cfset structInsert( passArgs, "SCMID", rs_failure_option.scm_id, true ) />
											<tr class="cellDivide">
												<td><cfoutput>#rs_failure_option.course_name#</cfoutput></td>
												<td><cfoutput>#rs_failure_option.prop_name#</cfoutput></td>
												<td align="center"><span class="number"><cfoutput>#numberFormat( rs_failure_option.course_credit, "_.__" )#</cfoutput></span></td>
												<td align="center">
													<cfif isNumeric(markFinal)>
															<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
														<cfelse>
															<cfoutput>#markFinal#</cfoutput>
													</cfif>
												</td>
												<td><a title="指定替代成绩" href="<cfoutput>#buildURL('signMarkReplace', passArgs)#</cfoutput>" class="operation replaceCourse"></a></td>
											</tr>

										</cfloop>
										<!--- 移除额外参数 --->
										<cfset structDelete( passArgs, "SCMID", false ) />
									</tbody>
								
								</table>
							
							</cfif>
							

						</div>
						
					</div>
					